package com.jr.platform.generator.CodeGen;

import cn.hutool.core.util.EnumUtil;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.StrUtil;
import cn.hutool.json.JSONArray;
import cn.hutool.json.JSONObject;
import cn.hutool.json.JSONUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.StringPool;
import com.baomidou.mybatisplus.generator.AutoGenerator;
import com.baomidou.mybatisplus.generator.InjectionConfig;
import com.baomidou.mybatisplus.generator.config.*;
import com.baomidou.mybatisplus.generator.config.po.TableField;
import com.baomidou.mybatisplus.generator.config.po.TableInfo;
import com.baomidou.mybatisplus.generator.config.rules.IColumnType;
import com.baomidou.mybatisplus.generator.config.rules.NamingStrategy;
import com.baomidou.mybatisplus.generator.engine.FreemarkerTemplateEngine;
import com.jr.platform.domain.*;
import com.jr.platform.domain.Enums.ColumTypeEnum;
import com.jr.platform.service.*;
import lombok.RequiredArgsConstructor;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Component;

import java.util.*;
import java.util.concurrent.atomic.AtomicReference;
import java.util.stream.Collectors;

/**
 * @author xy
 */
@Component
@RequiredArgsConstructor
public class CodeGenCore {

    private final CustomInterfaceService customInterfaceService;

    private final AutoTableService autoTableService;

    private final RedisTemplate redisTemplate;

    private final RequestHeaderService requestHeaderService;

    private final RequestParamsService requestParamsService;

    private final AutoTableColumnService autoTableColumnService;

    public Map<String,StringBuilder> sqlmap = new HashMap<>();
    public Map<String,List<Map<String,String>>> tableMap = new HashMap<>();
    private Set tableNameSet = new HashSet();

    private Map<String,String> tableIds = new HashMap<>();

    public void contextLoads(String json) {
        CustomInterface customInterface = JSONUtil.toBean(json, CustomInterface.class);
        JSONObject data = JSONUtil.getByPath(new JSONObject(customInterface.getResult()), "data", new JSONObject());
        createTable(data,"parent","0",Optional.ofNullable((Long)data.get("id")).orElse(null));
        //保存数据入库
        customInterface.setRelationTables(JSONUtil.toJsonStr(tableMap));
        //保存入redis
        redisTemplate.opsForHash().put("Interface",customInterface.getInterfaceName(),customInterface);
        customInterfaceService.saveOrUpdate(customInterface);
        //解析header
        JSONArray headers = JSONUtil.parseArray(customInterface.getHeader());
        List<RequestHeader> headerList = JSONUtil.toList(headers, RequestHeader.class);
        headerList.forEach(x->{
            x.setInterfaceId(customInterface.getId());
        });
        //保存入库
        requestHeaderService.saveBatch(headerList);
        //解析params
        JSONArray params = JSONUtil.parseArray(customInterface.getParams());
        List<RequestParams> paramsList = JSONUtil.toList(params, RequestParams.class);
        paramsList.forEach(x->{
            x.setInterfaceId(customInterface.getId());
        });
        //保存入库
        requestParamsService.saveBatch(paramsList);
        //拼装所有的sql并创建表
        sqlmap.forEach((k,v)->{
            v.append("primary key(id)) engine=innoDB default charset=utf8;");
            //TODO 建表和生成代码分开
            //获取当前表的子对象
            List<Map<String, String>> maps = tableMap.get(k);
            //遍历判断是否为修改表
            if(tableIds.get(k)==null){
                    //不是修改表则创建表
                    customInterfaceService.creatTable(v.toString());
            }
            //获取自动生成表状态为弃用的字段
            Map<String, String> collect = autoTableService.list(new QueryWrapper<AutoTable>().eq("status","1")).stream().collect(Collectors.toMap(AutoTable::getTableName, AutoTable::getStatus));
            if(collect.get(k)==null){
                //再生成代码
                if(StrUtil.contains(k,"parent")){
                    generatorParentCode(k,maps);
                }else {
                    generatorCode(k,maps);
                }
            }

        });
    }
    /**
     * 解析result
     * @param data
     * @param tableName
     */
    public void createTable(JSONObject data ,String tableName,String status,Long id){
        //判断当前表名称生成的次数
        int count = autoTableService.count(new LambdaQueryWrapper<AutoTable>().eq(AutoTable::getParamName, tableName));
        //存入数据库
        AutoTable autoTable = new AutoTable();
        autoTable.setParamName(tableName);
        autoTable.setId(id);
        autoTable.setRepetCount(StrUtil.toString(count));
        autoTable.setTableName(tableName+"_table"+StrUtil.toString(count));
        autoTable.setStatus(status);
        autoTableService.saveOrUpdate(autoTable);
        //第一次创建建表语句
        StringBuilder sql2 = new StringBuilder("CREATE TABLE IF NOT EXISTS  "+ autoTable.getTableName()+" ( id bigint auto_increment COMMENT '主键', parentid bigint COMMENT '父id',");
        //放入map方便后面根据key寻找
        sqlmap.put(autoTable.getTableName(),sql2);
        tableMap.put(autoTable.getTableName(),new ArrayList<>());
        tableIds.put("tableName",data.get("id")!=null?data.get("id").toString():null);
        tableNameSet.add(tableName);
        //保存主键id
        AutoTableColumn autoTableColumn =new AutoTableColumn();
        autoTableColumn.setColumnName("id");
        autoTableColumn.setColumnComment("主键");
        autoTableColumn.setTableId(autoTable.getId());
        autoTableColumn.setIsPk("1");
        autoTableColumn.setIsIncrement("1");
        autoTableColumn.setIsRequired("1");
        autoTableColumn.setJavaField("id");
        autoTableColumn.setJavaType("Long");
        autoTableColumnService.saveOrUpdate(autoTableColumn);
        data.forEach((k,v)->{
            JSONObject entries = JSONUtil.parseObj(v);
            //类型是Object
            if(StrUtil.equals(entries.get("type").toString(),"object")){
                Map<String,String> hashMap = new HashMap<>();
                int countK = autoTableService.count(new LambdaQueryWrapper<AutoTable>().eq(AutoTable::getParamName, k));
                //对象类首字母大写并拼接
                hashMap.put("type",StrUtil.upperFirst(k)+"Table"+countK);
                hashMap.put("value",k);
                hashMap.put("status",entries.get("status").toString());
                tableMap.get(autoTable.getTableName()).add(hashMap);
                createTable(JSONUtil.parseObj(entries.get("info")),k.toString(),entries.get("status").toString(),Optional.ofNullable((Long)entries.get("id")).orElse(null));
            } else
            //类型是List
            if(StrUtil.equals(entries.get("type").toString(),"list")){
                //并且类型是object
                Optional<Object> info = Optional.ofNullable(entries.get("info"));
                info.ifPresent(val->
                        {
                            Map<String,String> hashMap =new HashMap<>();
                            int countK = autoTableService.count(new LambdaQueryWrapper<AutoTable>().eq(AutoTable::getParamName, k));
                            hashMap.put("type","List<"+StrUtil.upperFirst(k)+"Table"+countK+">");
                            hashMap.put("value",k);
                            hashMap.put("status",entries.get("status").toString());
                            tableMap.get(autoTable.getTableName()).add(hashMap);
                            //设置表状态
                            createTable(JSONUtil.parseObj(val),k.toString(),entries.get("status").toString(),Optional.ofNullable((Long)entries.get("id")).orElse(null));
                        }
                );
            } else {
                Map<String, Object> enumMap = EnumUtil.getNameFieldMap(ColumTypeEnum.class, "value");
                sqlmap.get(autoTable.getTableName()).append(k+" "+enumMap.get(entries.get("type").toString().toUpperCase())+" comment '"+entries.get("comment").toString()+"',");
                //保存表字段
                //TODO 添加备注
                autoTableColumn.setColumnName(k);
                autoTableColumn.setColumnId(Optional.ofNullable((Long)entries.get("id")).orElse(null));
                autoTableColumn.setColumnComment(entries.get("comment").toString());
                autoTableColumn.setTableId(autoTable.getId());
                autoTableColumn.setStatus(entries.get("status").toString());
                autoTableColumn.setIsPk("0");
                autoTableColumn.setIsIncrement("0");
                autoTableColumn.setIsRequired("0");
                autoTableColumn.setJavaField(k);
                autoTableColumn.setJavaType(entries.get("type").toString());
                autoTableColumnService.saveOrUpdate(autoTableColumn);
            }
        });
    }

    void generatorCode(String tableName,List<Map<String, String>> childrenTable){
        // 代码生成器
        AutoGenerator mpg = new AutoGenerator();
        // 全局配置
        GlobalConfig gc = new GlobalConfig();
        String projectPath = System.getProperty("user.dir");
        gc.setOutputDir(projectPath + "/src/main/java");
        gc.setAuthor("xy");
        gc.setOpen(false);
        // gc.setSwagger2(true); 实体属性 Swagger2 注解
        mpg.setGlobalConfig(gc);

        // 数据源配置
        DataSourceConfig dsc = new DataSourceConfig();
        // dsc.setSchemaName("public");
        dsc.setUrl("jdbc:mysql://61.191.55.222:3389/platform?useUnicode=true&characterEncoding=utf-8&serverTimezone=UTC&useSSL=false");
        dsc.setDriverName("com.mysql.cj.jdbc.Driver");
        dsc.setUsername("root");
        dsc.setPassword("jrttah20221208.");
        mpg.setDataSource(dsc);

        // 包配置
        PackageConfig pc = new PackageConfig();
        pc.setModuleName("plat");
        pc.setParent("com.jr.auto");
        pc.setEntity("entity");
        pc.setMapper("mapper");
        pc.setXml("mapper.mapping");
        pc.setService("service");
        pc.setServiceImpl("service.impl");
        pc.setController("");
        mpg.setPackageInfo(pc);

        // 自定义配置
        InjectionConfig cfg = new InjectionConfig() {
            @Override
            public void initMap() {

            }
        };
        // 自定义输出配置
        List<FileOutConfig> focList = new ArrayList<>();
        mpg.setCfg(cfg);

        // 配置模板
        TemplateConfig templateConfig = new TemplateConfig();
        // 配置自定义输出模板
        templateConfig.setXml("/templates/test/mapper.xml");
        templateConfig.setEntity("/templates/test/entity.java");
        templateConfig.setController("");
        templateConfig.setService("/templates/test/service.java");
        templateConfig.setServiceImpl("/templates/test/serviceImpl.java");
        templateConfig.setMapper("/templates/test/mapper.java");
        mpg.setTemplate(templateConfig);
        // 策略配置
        StrategyConfig strategy = new StrategyConfig();
        strategy.setNaming(NamingStrategy.underline_to_camel);
        strategy.setColumnNaming(NamingStrategy.underline_to_camel);
        strategy.setEntityLombokModel(true);
        strategy.setInclude(tableName);
        mpg.setStrategy(strategy);
        mpg.setTemplateEngine(new FreemarkerTemplateEngine());
        // 如果模板引擎是 freemarker
        String templatePath = "/templates/test/entity.java.ftl";
        //获取自动生成表状态为弃用的字段
        Map<String, String> collect = autoTableService.list(new QueryWrapper<AutoTable>().eq("table_name", tableName).eq("status","1")).stream().collect(Collectors.toMap(AutoTable::getParamName, AutoTable::getStatus));
        //获取自动生成表
        AutoTable one = autoTableService.getOne(new QueryWrapper<AutoTable>().eq("table_name", tableName));
        //获取字段状态为弃用的字段
        Map<String, String> stringMap = autoTableColumnService.list(new QueryWrapper<AutoTableColumn>().eq("table_id",one.getId()).eq("status","1")).stream().collect(Collectors.toMap(AutoTableColumn::getColumnName, AutoTableColumn::getStatus));
        //合并map
        collect.putAll(stringMap);
        // 自定义配置会被优先输出
        focList.add(new FileOutConfig(templatePath) {
            @Override
            public String outputFile(TableInfo tableInfo) {
                List<TableField> tableFields = tableInfo.getFields();
                //过滤tableField基本字段并移除
                List<TableField> value = tableFields.stream().filter(f -> collect.get(f.getPropertyName())!=null).collect(Collectors.toList());
                value.forEach(v->{
                    tableInfo.getFields().remove(v);
                });
                //新增字段 修改tableFiled
                if (childrenTable.size()>0){
                    childrenTable.forEach(x->{
                        //过滤tableField对象字段并移除
                        if(StrUtil.equals(x.get("status").toString(),"0")) {
                            tableInfo.getImportPackages().add("com.baomidou.mybatisplus.annotation.TableField");
                            TableField tableField = new TableField();
                            tableField.setName(x.get("value"));
                            //当前总数减一
                            int countK = autoTableService.count(new LambdaQueryWrapper<AutoTable>().eq(AutoTable::getParamName, x.get("value"))) - 1;
                            tableInfo.getImportPackages().add(pc.getParent() + "." + pc.getEntity() + "." + StrUtil.upperFirst(x.get("value") + "Table" + countK));
                            tableField.setType(x.get("type"));
                            if (x.get("type").contains("List")) {
                                tableInfo.getImportPackages().add("java.util.List");
                            }
                            for (int i = 0; i < tableFields.size(); i++) {
                                if (StrUtil.equals(tableFields.get(i).getPropertyName(), x.get("value"))) {
                                    tableFields.remove(i);
                                    break;
                                }
                            }
                            //设置propertyType
                            tableField.setColumnType(new IColumnType() {
                                @Override
                                public String getType() {
                                    return x.get("type");
                                }

                                @Override
                                public String getPkg() {
                                    return pc.getParent() + "." + pc.getEntity() + x.get("value");
                                }
                            });
                            tableField.setPropertyName(x.get("value"));
                            tableInfo.getFields().add(tableField);
                        }
                    });
                }
                // 自定义输出文件名 ， 如果你 Entity 设置了前后缀、此处注意 xml 的名称会跟着发生变化！！
                String platPath = StrUtil.replace(pc.getParent(),".","/");
                return projectPath + "/src/main/java/"+platPath+"/"+pc.getEntity()+"/"+tableInfo.getEntityName() + "" + StringPool.DOT_JAVA;            }
        });
        cfg.setFileOutConfigList(focList);
        mpg.execute();
    }
    void generatorParentCode(String tableName,List<Map<String, String>> childrenTable){
        // 代码生成器
        AutoGenerator mpg = new AutoGenerator();
        // 全局配置
        GlobalConfig gc = new GlobalConfig();
        String projectPath = System.getProperty("user.dir");
        gc.setOutputDir(projectPath + "/src/main/java");
        gc.setAuthor("xy");
        gc.setOpen(false);
        // gc.setSwagger2(true); 实体属性 Swagger2 注解
        mpg.setGlobalConfig(gc);

        // 数据源配置
        DataSourceConfig dsc = new DataSourceConfig();
        // dsc.setSchemaName("public");
        dsc.setUrl("jdbc:mysql://61.191.55.222:3389/platform?useUnicode=true&characterEncoding=utf-8&serverTimezone=UTC&useSSL=false");
        dsc.setDriverName("com.mysql.cj.jdbc.Driver");
        dsc.setUsername("root");
        dsc.setPassword("jrttah20221208.");
        mpg.setDataSource(dsc);

        // 包配置
        PackageConfig pc = new PackageConfig();
        pc.setModuleName("plat");
        pc.setParent("com.jr.auto");
        pc.setEntity("entity");
        pc.setMapper("mapper");
        pc.setXml("mapper.mapping");
        pc.setService("service");
        pc.setServiceImpl("service.impl");
        pc.setController("");
        mpg.setPackageInfo(pc);

        // 自定义配置
        InjectionConfig cfg = new InjectionConfig() {
            @Override
            public void initMap() {

            }
        };
        // 自定义输出配置
        List<FileOutConfig> focList = new ArrayList<>();
        mpg.setCfg(cfg);
        // 配置模板
        TemplateConfig templateConfig = new TemplateConfig();
        // 配置自定义输出模板
        templateConfig.setXml("/templates/test/mapper.xml");
        templateConfig.setEntity("/templates/test/entity.java");
        templateConfig.setController("");
        templateConfig.setService("/templates/test/pService.java");
        templateConfig.setServiceImpl("/templates/test/pServiceImpl.java");
        templateConfig.setMapper("/templates/test/mapper.java");
        mpg.setTemplate(templateConfig);

        // 策略配置
        StrategyConfig strategy = new StrategyConfig();
        strategy.setNaming(NamingStrategy.underline_to_camel);
        strategy.setColumnNaming(NamingStrategy.underline_to_camel);
        strategy.setEntityLombokModel(true);
        strategy.setInclude(tableName);
        mpg.setStrategy(strategy);
        mpg.setTemplateEngine(new FreemarkerTemplateEngine());
        // 如果模板引擎是 freemarker
        String templatePath = "/templates/test/entity.java.ftl";
        //获取自动生成表状态
        Map<String, String> collect = autoTableService.list(new QueryWrapper<AutoTable>().eq("table_name", tableName)).stream().collect(Collectors.toMap(AutoTable::getParamName, AutoTable::getStatus));
        //获取自动生成表
        AutoTable one = autoTableService.getOne(new QueryWrapper<AutoTable>().eq("table_name", tableName));
        //获取字段状态
        Map<String, String> stringMap = autoTableColumnService.list(new QueryWrapper<AutoTableColumn>().eq("table_id",one.getId())).stream().collect(Collectors.toMap(AutoTableColumn::getColumnName, AutoTableColumn::getStatus));
        //合并map
        collect.putAll(stringMap);
        // 自定义配置会被优先输出
        focList.add(new FileOutConfig(templatePath) {
            @Override
            public String outputFile(TableInfo tableInfo) {
                List<TableField> tableFields = tableInfo.getFields();
                //过滤tableField基本字段并移除
                List<TableField> value = tableFields.stream().filter(f -> collect.get(f.getPropertyName())!=null).collect(Collectors.toList());
                if(value.size()>0){
                    childrenTable.remove(value.get(0));
                }
                //新增字段 修改tableFiled
                if (childrenTable.size()>0){
                    childrenTable.forEach(x->{
                        //过滤tableField对象字段并移除
                        if(StrUtil.equals(x.get("status").toString(),"0")) {
                            List<TableField> ObjectVal = tableFields.stream().filter(f -> collect.get(f.getPropertyName()) != null).collect(Collectors.toList());
                            tableInfo.getImportPackages().add("com.baomidou.mybatisplus.annotation.TableField");
                            if (ObjectVal.size() == 0 || StrUtil.equals(ObjectVal.get(0).getPropertyName(), x.get("value"))) {
                                TableField tableField = new TableField();
                                tableField.setName(x.get("value"));
                                int countK = autoTableService.count(new LambdaQueryWrapper<AutoTable>().eq(AutoTable::getParamName, x.get("value"))) - 1;
                                tableInfo.getImportPackages().add(pc.getParent() + "." + pc.getEntity() + "." + StrUtil.upperFirst(x.get("value") + "Table" + countK));
                                tableInfo.setControllerName(StrUtil.join(",", tableNameSet));
                                tableField.setType(x.get("type"));
                                if (x.get("type").contains("List")) {
                                    tableInfo.getImportPackages().add("java.util.List");
                                }
                                for (int i = 0; i < tableFields.size(); i++) {
                                    if (StrUtil.equals(tableFields.get(i).getPropertyName(), x.get("value"))) {
                                        tableFields.remove(i);
                                        break;
                                    }
                                }
                                //设置propertyType
                                tableField.setColumnType(new IColumnType() {
                                    @Override
                                    public String getType() {
                                        return x.get("type");
                                    }
                                    @Override
                                    public String getPkg() {
                                        return pc.getParent() + "." + pc.getEntity() + x.get("value");
                                    }
                                });
                                tableField.setPropertyName(x.get("value"));
                                tableInfo.getFields().add(tableField);
                            }
                        }
                    });
                }
                // 自定义输出文件名 ， 如果你 Entity 设置了前后缀、此处注意 xml 的名称会跟着发生变化！！
                String platPath = StrUtil.replace(pc.getParent(),".","/");
                return projectPath + "/src/main/java/"+platPath+"/"+pc.getEntity() +"/"+ tableInfo.getEntityName() + "" + StringPool.DOT_JAVA;
            }
        });
        cfg.setFileOutConfigList(focList);
        mpg.execute();
    }

    /**
     * 解析table
     * @param childrens
     * @param sql
     */
    public void childrenTables(List childrens,StringBuilder sql){
        childrens.forEach(ch ->{
            Map map = JSONUtil.parseObj(ch);
            map.forEach((k,v)->{
                if(StrUtil.equals(k.toString(),"children")){
                    if(v!=null&& !v.equals("")){
                        List<String> stringList = JSONUtil.parseArray(v).toList(String.class);
                        childrenTables(stringList,sql);
                    }
                } else
                if(StrUtil.equals(k.toString(),"tableName")){
                    sql.append("CREATE TABLE IF NOT EXISTS  "+ v.toString()+"( id bigint auto_increment,");
                } else {
                    Map<String, Object> enumMap = EnumUtil.getNameFieldMap(ColumTypeEnum.class, "value");
                    sql.append(k+" "+ enumMap.get(v.toString().toUpperCase())+",");
                }
            });
            sql.append("primary key(id)) engine=innoDB default charset=utf8;");
        });
    }
    List<FileOutConfig> childCode(List<String> list,List<FileOutConfig> focList, String projectPath,PackageConfig pc){
        list.forEach(ch ->{
            Map map = JSONUtil.parseObj(ch);
            List<TableField> fields = new ArrayList<>();
            AtomicReference<String> fieldsName = new AtomicReference<>("");
            AtomicReference<String> entityName = new AtomicReference<>("");
            map.forEach((k,v)->{
                if(StrUtil.equals(k.toString(),"children")){
                    if(ObjectUtil.isNotEmpty(v)){
                        List<String> stringList = JSONUtil.parseArray(v).toList(String.class);
                        stringList.forEach(sts ->{
                            //将自定义vo字段传入fields
                            Map smap = JSONUtil.parseObj(sts);
                            TableField tableField =new TableField();
                            tableField.setName(smap.get("className").toString());
                            tableField.setType(smap.get("type").toString());
                            tableField.setPropertyName(smap.get("className").toString());
                            fieldsName.set(fieldsName.get()+smap.get("className").toString());
                            fields.add(tableField);
                        });
                        childCode(stringList,focList,projectPath,pc);
                    }
                } else if(StrUtil.equals(k.toString(),"className")){
                    entityName.set(v.toString());
                } else if(StrUtil.equals(k.toString(),"type")){
                }
                else {
                    //添加其他字段
                    TableField tableField =new TableField();
                    tableField.setName(k.toString());
                    tableField.setType(v.toString());
                    tableField.setPropertyName(k.toString());
                    fieldsName.set(fieldsName.get().length()>0?fieldsName.get()+","+k.toString():fieldsName.get()+k.toString());
                    fields.add(tableField);
                }
            });

            // 如果模板引擎是 freemarker
            String templatePath = "/templates/test/vo.java.ftl";

            // 自定义配置会被优先输出
            focList.add(new FileOutConfig(templatePath) {
                @Override
                public String outputFile(TableInfo tableInfo) {
                    tableInfo.setFields(fields);
                    tableInfo.setEntityName(entityName.get());
                    tableInfo.setName(entityName.get());
//                    tableInfo .setFieldNames(fieldsName.get());
                    // 自定义输出文件名 ， 如果你 Entity 设置了前后缀、此处注意 xml 的名称会跟着发生变化！！
                    return projectPath + "/src/main/java/com/js/platform/"+pc.getModuleName()+"/entity/vo/" + entityName.get() + "" + StringPool.DOT_JAVA;
                }
            });
        });
        return focList;
    }

//    @Test
//    void  tessss(){
//        String json = "{'result1':'result1Value','result2':2.2,'result3':{'result31':'result31Value','result32':'2022-12-22 10:11:25','result33':[{'result331':'result331Value','result332':'result332Value'},{'result331':'result331Value2','result332':'result332Value2'}],'result34':[{'result341':'result341Value','result342':[{'result3421':'result3421Value'},{'result3422':'result3422Value'}],'result343':343.3},{'result341':'result341Value2','result342':[{'result3421':'result3421Value2'},{'result3422':'result3422Value2'}],'result343':343.4}],'result35':{'result351':'result351Value','result352':35.2}}}";
//        ParentTable parentTable = JSONUtil.toBean(json, ParentTable.class);
//        String childs = "parent,result33,result34,result35,result3,result342";
//        List<String> strings = Arrays.asList(childs.split(","));
//        extracted(parentTable, strings, null);
//}
//
//    private  void extracted(Object clazz, List<String> strings,Long id) {
//        Object bean = SpringUtil.getBean(clazz.getClass().getSimpleName()+"ServiceImpl");
//        Method method = ReflectionUtils.findMethod(bean.getClass(), "save", clazz.getClass());
////        Method setId = ReflectionUtils.findMethod(clazz.getClass(), "setId", Long.class);
////        ReflectionUtils.invokeMethod(setId, bean, id);
//        ReflectionUtils.invokeMethod(method, bean, clazz);
//        List<Field> fields = Arrays.asList(clazz.getClass().getDeclaredFields());
//        Map<String, Field> collects = fields.stream().collect(Collectors.toMap(Field::getName, Function.identity()));
//        strings.forEach(x->{
//            if(collects.get(x)!=null){
//                if(collects.get(x).getType().isInstance(List.class)){
//
//                }else {
//                    Object fieldsValue =  ReflectUtil.getFieldValue(collects.get(x),x);
//                    extracted(fieldsValue,strings,(Long) ReflectUtil.getFieldValue(clazz,"id"));
//                }
//            }
//        });
//    }

}

